package twentytwenty;

/**
 * @Author: Spider Man
 * @Description: 1154.一年中的第几天
 * @Date Created in 2020-09-26 11:08
 * @Modified By:
 */
public class DayOfYear_1154 {
    public static void main(String[] args) {
        String date = "2003-03-01";
        System.out.println(dayOfYear(date));
    }

    public static int dayOfYear(String date) {
        // 题目中已经说明了给的data是固定类型的，所以不用做特殊帕努单

        // 1.将给的data字符串由"-"符号拆成数组，数组中的元素分别包括年月日信息
        String[] split = date.split("-");

        // 2.将字符串的数组转换为数字的数组存储
        int [] year = new int[3];
        for (int i = 0; i < 3; i++) {
            year[i] = Integer.parseInt(split[i]);
        }

        // 逻辑判断，平闰年，大小月
        int [] dayOfMouth = new int[]{0,31,28,31,30,31,30,31,31,30,31,30,31};
        int count = 0;
        if((year[0] % 4 == 0 && year[0] % 100 != 0) || (year[0] % 400 == 0)){
            dayOfMouth[2] = 29;
        }
        for(int i = 0;i < year[1]; i++){
            count += dayOfMouth[i];
        }
        return count + year[2];
    }
}
